ABC133 C - Remainder Minimization 2019
提出
WA/TLE
code: python
l, r = map(int,input().split())
nums = set()
ans = float('inf')
flag = True
for i in range(l, r+1):
if (flag):
for j in range(i+1, r+1):
res = (i * j) % 2019
if (res in nums):
flag = False
else:
nums.add(res)
if (res < ans):
ans = res
print(ans)
解答
code: python
l, r = map(int,input().split())
nums = set()
ans = float('inf')
for i in range(l, r):
for j in range(i+1, r+1):
res = (i * j) % 2019
if (res < ans):
ans = res
if (ans == 0):
print(0)
exit()
print(ans)
メモ
(x×y)mod2019 = ((xmod2019) × (ymod2019))mod2019
i % 2019をiを増やしながら考えていくと、最悪でも2019個以内に0になるものが存在する
解答
code: python
l, r = map(int, input().split())
# mod2019
# iが決まる -> i + 2019 or i + 1
# 短調増加